﻿Imports Mystery

Public Class ContentAddButton(Of T As IContent)
    Implements IButton


    Public Event Clicked() Implements IButton.Clicked
    Private _content_type As ContentType

    Private _image_uri As Uri

    Public Sub New()
        _content_type = getMystery.AssemblyRegister.getMysteryClassAttribute(Of ContentType, T)()
        Dim cb As ContentButtonAttribute = getMystery.AssemblyRegister.getMysteryClassAttribute(Of ContentButtonAttribute, T)()

        If String.IsNullOrEmpty(cb.normal_icon) Then
            _image_uri = New Uri("Images/object.png", UriKind.Relative)
        Else
            _image_uri = New Uri(cb.normal_icon, UriKind.RelativeOrAbsolute)
        End If
    End Sub

    Public Function getImage() As System.Windows.Controls.Image Implements IButton.getImage
        Dim result As New Image()
        result.Source = New BitmapImage(_image_uri)
        Return result
    End Function

    Public Function getText() As String Implements IButton.getText
        Return "New " & _content_type.label
    End Function

    Public Sub Press() Implements IButton.Press
        getGlobalObject(Of InterfaceStatus)().addType(GetType(T), Nothing)
        RaiseEvent Clicked()
    End Sub

End Class
